package com.jungle.sp.daily;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

public class CurrentMonthTraversal {
    public static void main(String[] args) {
        LocalDate today = LocalDate.of(2024, 6, 30);
        LocalDate localDate = today.minusMonths(1);
        System.out.println(localDate);
        // UserDto userDto = new UserDto(1L,"120");
        // List<UserDto> list = Arrays.asList(userDto);
        // list = null;
        // Map<Long, String> collect = ListUtils.emptyIfNull(list).stream().collect(Collectors.toMap(UserDto::getId, UserDto::getName));
        // Set<Long> longs = collect.keySet();
        // System.out.println(longs);
        // m1();
    }

    private static void m1() {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now().minusMonths(1);
        // 创建一个表示当前年月的YearMonth实例
        YearMonth currentYearMonth = YearMonth.from(currentDate);
        // 获取当月的第一天
        LocalDate firstDayOfMonth = currentYearMonth.atDay(1);
        // 获取当月的天数
        int daysInMonth = currentYearMonth.lengthOfMonth();
        // 定义一个日期格式化器（可选）
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 遍历当月的每一天
        for (int day = 1; day <= daysInMonth; day++) {
            // 计算当前遍历到的日期
            LocalDate date = firstDayOfMonth.plusDays(day - 1);
            // 输出当前日期
            System.out.println("日期: " + date.format(formatter));
        }
    }
}
